stored procedure to generate 1000 data in the T_team table and 100,000 data in the T_people table. (Stored procedure at the end of this article)
Execute the above SQL statement several times, taking about 3 seconds.
Another two statements to compare:
1. Remove the ORDER BY clause: SELECT * from T_people p LEFT join T_team T on P.team_id=t.id limit10; [Statement ②]
Takes 0.00 seconds, negligible.
2. Or us
MySQL ORDER BY syntax
The code is as follows
Copy Code
SELECT column_name (s) from table_name ORDER BY column_name
NOTE: The SQL statement is a "letter case insensitive" statement (it does not distinguish between uppercase and lowercase letters), that is, "order by" is the same as the "by".
MySQL ORDER BY case
The following example: Select all the records from the pe
Label: Today, there is a problem with a SELECT statement that does not have an "Order by" and the returned data is indeterminate. This kind of problem has met more than a few times. Traced, if the SELECT statement does not add "order by", how will MySQL be sorted? Searched the Internet and found this article in the MySQL forum. http://forums.mysql.com/read.php?21,239471,239688#msg-239688 A simple translatio
Oracle experiences 1 -- oracle introduction @ basic SQL statement @ conditional query @ sort data theory and case studies1. Oracle IntroductionOracle is the first word for English translation of oracle (Oracle bone inscriptions) Unearthed from Yin. Oracle is the world's largest supplier of information management software and services. It was founded in 1977 and is headquartered in Redwood shore, California.
Query, delete, insert, query, sort SQL statementHere we provide query, delete, insert, query, sort totals sum average max minimum SQL statement OH.Selection: SELECT * FROM table1 whereInserting: INSERT INTO table1 (field1,field2) VALUES (value1,value2)Delete: Delete from table1 where scopeUpdate: UPDATE table1 set field1=value1 where scopeFind: SELECT * FROM tabl
time the annual salary SELECT ename, job, (sal+300 *12+sal income from emp;--Company will make a one-month base salary SELECT empno at the end of each year | ',' || Ename from emp;--can also use the "| |" in a simple query
The field of the connection query. SELECT ' Employee number is: ' | | Empno | | ' The employee's name is: ' | | ename | | ', the basic salary is: ' | | Sal | | ', the position is: ' | | Job | | '!
' Employee information from emp;--requires that the current database be disp
Database query results can not be used directly, such as MySQL, such as the results in the statement, so you need to sort the results in some way.Example 4. To sort the results of a database
In this example, each cell in the data array represents a row in a table. This is a typical collection of data for database records.
The data in the example are as follows:
V
When a data query on a single table 5000W data is passed two single-column index criteria, when a composite index query, if the last order by ID sort, and remove the sort, the performance gap is close to two orders of magnitudeConclusion: When using the default ordering of columns, you should not order by the columnBy the way, record the other SQL performance issues encountered:1, limit A, or a value is too
);}Output information for all elements in the struct arrayvoid Printallstudent (Student * stus, int count) {for (int i = 0; i Printstudent (Stus+i);}}Sort by name Ascendingvoid Sortascendbyname (Student * stus, int count) {for (int i = 0; i for (int j = 0; J if (strcmp (Stus[j].names, Stus[j+1].names) > 0) {Student temp = stus[j];STUS[J] = stus[j+1];STUS[J+1] = temp;}}}}In descending order of agevoid Sortdescendbyage (Student * stus, int count) {for (
A few days to a company in Pudong to interview, feel that there is a database query questions did not answer well, self-summary, the next attention.Title: The size of tables in the database, and arranged out. Write the corresponding SQL statement.The code is as follows:CREATE PROCEDURE [dbo].[Gettablespace]@dbNamesysname= "',--database name, default current database@tableNamesysname= "',--table name, default all tables@columnName varchar( -)= "',--column names, sorting with@
Sort a two-dimensional array BY a specified column, similar to ORDERBY in an SQL statement. Sort a two-dimensional array BY a specified column, similar to order by in an SQL statement.
Script ec (2); script
/*** Sort the Array Based on the specified key value** @ Param ar
In SQL server, you can use SQL statements to sort by the first letter of a Chinese character. For example, we often use "sort by the first letter of a name"
-- Replace tableName and colName with your own.-- Press pinyin
Alter table tableNameAlter column colName nvarchar (100) COLLATE Chinese_PRC_CI_ASSelect * from tableName order by colName
-- StrokeAlter table tableNameAlter column colName nvarchar (100) C
Orderbybtcountdesc or orderbybtcount is invalid. Is there any sort statement? Select * from table where yz = '1' order by btcount desc write output is incorrect,
The field btcount is very short. generally, it is = 0 or = 1, and the maximum value is = 8.
When the data volume is large, you cannot sort by the value of btcount greater than. why?
Which can be co
In MySQL, the default text field is sorted by the first character of the text field, that is, if a table structure is as follows:
If you sort the field by default for this text type, such as SELECT * FROM table ORDER by F1 ASC. The results may be as follows:
Find that MySQL sorts the fields of type text to just the first character, not the result we expected (sorted by number size).
So if you want to solve this
Label: string text = "SELECT * from [admin] where aa=1 and cc= ' B ' ORDER by AA Desc";Regex reg = null; reg = new Regex (@ "\s+from\s+.*?" ( \s+where\s+|\s+order\s+|\s+group\s+) |\s+from\s+.+ ", regexoptions.ignorecase);string table = Reg. Match (text).
Value; Table = Regex.Replace (table. ToLower (), @ "\s+from\s+|\s+where\s+|\[|\]|\s+order\s+|\s+group\s+", "" ");reg = new Regex (@ "select\s+.*?\s+from\s+", regexoptions.ignorecase); String field = Reg. Match (text). Value;field = Regex
Database query results can not be used directly, such as MySQL, such as the results in the statement, so you need to sort the results in some way. Example 4. Sort database results Each cell in the data array in this example represents a row in a table. This is a typical collection of data for database records.
The data in the example are as follows:
Volume | Ed
Select a.ID as aid,b.id as bid,a.city,a.cang,a.sid,a.time as atime,b.time as btime,a.price as aprice,b.price as BPRICE,A.P M as apm,b.pm as BPM from (select Id,city,cang,sid,time,price, @rank: [e-mail protected]+1 as PM from Cai, (select @rank: =0) B GROUP BY Id,city,cang,time Order by City,cang,sid,time) as a, (select Id,city,cang,sid,time,price, @ranks: [Email protect Ed]+1 as PM from Cai, (SELECT @ranks: =0) b GROUP by Id,city,cang,time ORDER by City,cang,sid,time) as B where A.sid=b.sid and
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.